package com.sansi.bleFloodlight.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.github.gzuliyujiang.wheelpicker.contract.OnOptionSelectedListener;
import com.github.gzuliyujiang.wheelpicker.widget.OptionWheelLayout;

import com.my.httpapi.api.annotation.Layout;
import com.my.httpapi.api.baseView.BaseActivity;
import com.sansi.bleFloodlight.R;
import com.sansi.bleFloodlight.model.HaveTimeEvent;
import com.sansi.bleFloodlight.utils.Constant;
import com.sansi.bleFloodlight.utils.RouterPath;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Layout(R.layout.layout_activity_create_time)
@Route(path = RouterPath.createTimePath)
public class CreateTimeActivity extends BaseActivity {
    private OptionWheelLayout wheelOption1, wheelOption2, wheelOption3;
    private TextView tvWeek0, tvWeek1, tvWeek2, tvWeek3, tvWeek4, tvWeek5, tvWeek6, tvWeek, tvSave;

    private List<String> list1 = new ArrayList<>();
    private List<String> list2 = new ArrayList<>();

    private List<Boolean> weeStatus = new ArrayList<>();
    private String week = "every";

    @Autowired
    public int position;

    @Override
    protected void initView() {
        ARouter.getInstance().inject(this);
        wheelOption1 = findViewById(R.id.wheel_option_1);
        wheelOption2 = findViewById(R.id.wheel_option_2);
        wheelOption3 = findViewById(R.id.wheel_option_3);
        tvWeek0 = findViewById(R.id.tv_week_0);
        tvWeek1 = findViewById(R.id.tv_week_1);
        tvWeek2 = findViewById(R.id.tv_week_2);
        tvWeek3 = findViewById(R.id.tv_week_3);
        tvWeek4 = findViewById(R.id.tv_week_4);
        tvWeek5 = findViewById(R.id.tv_week_5);
        tvWeek6 = findViewById(R.id.tv_week_6);
        tvWeek = findViewById(R.id.tv_week);
        tvSave = findViewById(R.id.tv_save);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        for (int i = 0; i < 7; i++) {
            weeStatus.add(false);
        }
        for (int i = 0; i < 12; i++) {
            list1.add(i + "");
        }
        for (int i = 0; i < 60; i++) {
            list2.add(i + "");
        }
        wheelOption1.setData(list1);
        wheelOption2.setData(list2);
        wheelOption3.setData(Arrays.asList("AM", "PM"));

        wheelOption1.setOnOptionSelectedListener(new OnOptionSelectedListener() {
            @Override
            public void onOptionSelected(int position, Object item) {
            }
        });

        wheelOption2.setOnOptionSelectedListener(new OnOptionSelectedListener() {
            @Override
            public void onOptionSelected(int position, Object item) {

            }
        });

        wheelOption3.setOnOptionSelectedListener(new OnOptionSelectedListener() {
            @Override
            public void onOptionSelected(int position, Object item) {

            }
        });

        tvWeek0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (weeStatus.get(0)) {
                    weeStatus.set(0, false);
                    tvWeek0.setBackgroundResource(R.drawable.shape_light_preset);
                    week = week.replace(Constant.WEEK0, "");
                } else {
                    weeStatus.set(0, true);
                    tvWeek0.setBackgroundResource(R.drawable.shape_light_preset_blue);
                    week += Constant.WEEK0;
                }
                tvWeek.setText(week);
            }
        });

        tvWeek1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (weeStatus.get(1)) {
                    weeStatus.set(1, false);
                    tvWeek1.setBackgroundResource(R.drawable.shape_light_preset);
                    week = week.replace(Constant.WEEK1, "");
                } else {
                    weeStatus.set(1, true);
                    tvWeek1.setBackgroundResource(R.drawable.shape_light_preset_blue);
                    week += Constant.WEEK1;
                }
                tvWeek.setText(week);
            }
        });

        tvWeek2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (weeStatus.get(2)) {
                    weeStatus.set(2, false);
                    tvWeek2.setBackgroundResource(R.drawable.shape_light_preset);
                    week = week.replace(Constant.WEEK2, "");
                } else {
                    weeStatus.set(2, true);
                    tvWeek2.setBackgroundResource(R.drawable.shape_light_preset_blue);
                    week += Constant.WEEK2;
                }
                tvWeek.setText(week);
            }
        });

        tvWeek3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (weeStatus.get(3)) {
                    weeStatus.set(3, false);
                    tvWeek3.setBackgroundResource(R.drawable.shape_light_preset);
                    week = week.replace(Constant.WEEK3, "");
                } else {
                    weeStatus.set(3, true);
                    tvWeek3.setBackgroundResource(R.drawable.shape_light_preset_blue);
                    week += Constant.WEEK3;
                }
                tvWeek.setText(week);
            }
        });

        tvWeek4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (weeStatus.get(4)) {
                    weeStatus.set(4, false);
                    tvWeek4.setBackgroundResource(R.drawable.shape_light_preset);
                    week = week.replace(Constant.WEEK4, "");
                } else {
                    weeStatus.set(4, true);
                    tvWeek4.setBackgroundResource(R.drawable.shape_light_preset_blue);
                    week += Constant.WEEK4;
                }
                tvWeek.setText(week);
            }
        });

        tvWeek5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (weeStatus.get(5)) {
                    weeStatus.set(5, false);
                    tvWeek5.setBackgroundResource(R.drawable.shape_light_preset);
                    week = week.replace(Constant.WEEK5, "");
                } else {
                    weeStatus.set(5, true);
                    tvWeek5.setBackgroundResource(R.drawable.shape_light_preset_blue);
                    week += Constant.WEEK5;
                }
                tvWeek.setText(week);
            }
        });

        tvWeek6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (weeStatus.get(6)) {
                    weeStatus.set(6, false);
                    tvWeek6.setBackgroundResource(R.drawable.shape_light_preset);
                    week = week.replace(Constant.WEEK6, "");
                } else {
                    weeStatus.set(6, true);
                    tvWeek6.setBackgroundResource(R.drawable.shape_light_preset_blue);
                    week += Constant.WEEK6;
                }
                tvWeek.setText(week);
            }
        });

        tvSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(new HaveTimeEvent(1, position));
                finish();
            }
        });
    }

    @Override
    protected void destory() {

    }

    @Override
    protected String showTitle() {
        return "Create Scheduled Time";
    }

    @Override
    protected boolean statusBarIsBlack() {
        return false;
    }

    @Override
    protected boolean showLeftArrow() {
        return true;
    }
}
